import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Test3 {
    private static Set<Integer> primeSet;
    private static Set<Integer> vis;
    private static int path;
    private static int ret = 0x3f3f3f3f;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        primeSet = getPrimeSet();
        vis = new HashSet<>();
        dfs(nums, 0);
        System.out.println(ret == 0x3f3f3f3f ? -1 : ret);
    }

    private static void dfs(int[] nums, int index) {
        if (index >= nums.length) {
            ret = Math.min(ret, path);
            return;
        }
        int num = nums[index];
        for (Integer prime : primeSet) {
            if (num % prime == 0 && !vis.contains(prime)) {
                vis.add(prime);
                path += prime;
                dfs(nums, index+1);
                vis.remove(prime);
                path -= prime;
            }
        }
    }

    private static Set<Integer> getPrimeSet() {
        Set<Integer> set = new HashSet<>();
        for (int i = 2; i <= 1000; i++) {
            boolean flg = false;
            for (int j = 2; j <= i/2; j++) {
                if (i % j == 0) {
                    flg = true;
                    break;
                }
            }
            if (!flg) {
                set.add(i);
            }
        }
        return set;
    }
}
